Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding basic SSML support to Polly #737

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

dwm66
Copy link

@dwm66 dwm66 commented Dec 20, 2019

I recognized that the API basically could support SSML for AWS Polly.
The phrase of course has to encode all the SSML tags, so that a phrase like
<speak><prosody rate="90%">Hello</prosody></speak>
has to be sent as
http://mysonos:5005/Office/say/%3Cspeak%3E%3Cprosody%20rate%3D%2290%25%22%3EHello%3C%2Fprosody%3E%3C%2Fspeak%3E

Nevertheless, the phrase is sent correctly to AWS, the only "showstopper" is that in the AWS API call, the TextType is set to text.

I now added a few simple lines in the aws-polly.js provider, detecting the leading and ending "<speak>" tags in an SSML phrase and setting the TextType to "ssml" accordingly.

@metaxa1
Copy link

metaxa1 commented Dec 23, 2019

Hello, great thing, unfortunately it doesn't work for me:
http://192.168.0.96:5005/Wohnzimmer/say/Einen wunderschönen Abend! <prosody rate="slow"> Es ist jetzt Zeit mit der Zeit zu üben.</prosody>/Hans/30
Also
http://192.168.0.96:5005/Wohnzimmer/say/<speak>Jeden Morgen wenn ich aufwache, <prosody rate="slow"> spreche ich sehr langsam bis ich meinen ersten Cafe trinke. </prosody></speak>/Hans/30
unfortunately does not work. Yes, the typo is fixed to "TextType" and the service is restarted.
What am I doing wrong?
kr, mxa

Edit, for information only, this works perfectly without SSML.
http://192.168.0.96:5005/Wohnzimmer/say/Jeden Morgen wenn ich aufwache, spreche ich sehr langsam bis ich meinen ersten Cafe trinke./Hans/30

@dwm66
Copy link
Author

dwm66 commented Dec 23, 2019

Hello,
the characters <>/ .., are reserved characters, which must not be passed in the url.
The Sonos API tries to decode it, which does not work.

Therefore, you must use URL encoding to pass a SSML type phrase.
Please see: https://www.urlencoder.io/learn/

In order to encode your phrase, you can use something like https://www.urlencoder.org/
or - if calling it by Javascript, the encodeURI function.

Your example should work, if you call it like

http://192.168.0.96:5005/Wohnzimmer/say/%3Cspeak%3EJeden%20Morgen%20wenn%20ich%20aufwache%2C%20%3Cprosody%20rate%3D%22slow%22%3E%20spreche%20ich%20sehr%20langsam%20bis%20ich%20meinen%20ersten%20Cafe%20trinke.%20%3C%2Fprosody%3E%3C%2Fspeak%3E/Hans/30

@metaxa1
Copy link

metaxa1 commented Dec 24, 2019

Hi,
my browser FF encoded the respective url too, but that's wrong. Thanks to your explanation, I now use the JavaScript function as follows:

function encodemeins () { var url = '<speak>Jeden Morgen wenn ich aufwache, <prosody rate="x-slow"> spreche ich sehr langsam bis ich meinen ersten Cafe trinke. </prosody></speak>'; var url_enc = encodeURIComponent(url); var res = "http://192.168.0.96:5005/Wohnzimmer/say/"+ url_enc + "/Hans/30"; console.log(res); };

That is exactly how I imagined it to be, thank you for your work!

@chrisweather
Copy link

Hi,
I just tested the changes of dwm66 to announce either radio station name or artist, title. Works great with these short text inputs. Didn't test it with longer texts. These tags were used in my example: speak, break, prosody.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants